import os
import json
from multiprocessing import Pool 


input_files = os.listdir("./11.sub_parent")

output_dir = "./12.tree_concept_parent"
os.makedirs(output_dir, exist_ok=True)

tree = "./16.menu_tree_to_dict_embedding.json"


def exec(tree_embedding, label_tree_concept, output):
    cmd = f"python 12.label_tree_concept_parent.py -tree_embedding {tree_embedding} -label_tree_concept {label_tree_concept} -output {output}"
    os.system(cmd)
    
tasks = []
for file in input_files:
    input_file_path = os.path.join("./11.sub_parent", file)
    output_file_path = os.path.join("./12.tree_concept_parent", file.split(".")[0] + ".json")
    tasks.append((tree, input_file_path, output_file_path))

# for i in tasks:
#     print(i[1:])
#     exec(i[0], i[1], i[2])

with Pool(250) as pool:
    pool.starmap(exec, tasks)